package top.wuyang.springboot3.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.wuyang.springboot3.base.PageBean;
import top.wuyang.springboot3.base.R;
import top.wuyang.springboot3.entity.TbClass;
import top.wuyang.springboot3.service.TbClassService;
import top.wuyang.springboot3.vo.PageVO;

import java.util.List;

@RestController
@RequestMapping("/class")
@RequiredArgsConstructor
public class TbClassController {
    private final TbClassService tbClassService;

    @GetMapping("/queryAll")
    public R<PageVO<TbClass>> queryAll(PageBean pageBean, TbClass tbClass) {
        return tbClassService.queryPage(pageBean, tbClass);

    }


    //
    @GetMapping("/{pn}/{ps}")
    public R<PageVO<TbClass>> queryPage(@PathVariable("pn") Long pageNumber, @PathVariable("ps") Long pageSize, TbClass tbClass) {
        return tbClassService.queryPage(PageBean.instance(pageNumber, pageSize), tbClass);
    }


    // @PostMapping表示必须使用post请求 @RequestBody表示参数是json格式提交
    @PostMapping("")
    public R<String> insert(@RequestBody TbClass tbClass) {
        return tbClassService.insert(tbClass);
    }

    @GetMapping("")
    public R<List<TbClass>> query(TbClass tbClass) {
        return tbClassService.query(tbClass);
    }

    // @PathVariable表示路径参数
    @GetMapping("/{id}")
    public R<TbClass> queryById(@PathVariable("id") Integer id) {
        return tbClassService.queryById(id);
    }

    // 修改必须是@PutMapping
    @PutMapping("")
    public R<String> update(@RequestBody TbClass tbClass) {
        return tbClassService.update(tbClass);
    }


    // 删除必须是@DeleteMapping
    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbClassService.delete(id);
    }


}
